package com.dbexplore.db;

import com.dbexplore.db.structure.Table;
import com.dbexplore.db.structure.Column;
import com.dbexplore.db.structure.View;

import java.util.List;
import java.util.ArrayList;
import java.sql.SQLException;
import java.sql.ResultSet;

public class DatabaseGateway {

    public List<Table> getAllTables() throws SQLException {
        ResultSet rs = DBHelper.execute("SELECT ut.table_name, uc.constraint_name FROM user_tables ut, user_constraints uc WHERE ut.table_name= uc.table_name AND constraint_type='P'");
        List<Table> tables = new ArrayList<Table>();
        while (rs.next()) {
            Table table = new Table(rs.getString("table_name"), rs.getString("constraint_name"));
            tables.add(table);
        }
        return tables;
    }

    public List<View> getAllViews() throws SQLException {
        ResultSet rs = DBHelper.execute("SELECT view_name, text FROM user_views");
        List<View> views = new ArrayList<View>();
        while (rs.next()) {
            View view = new View(rs.getString("view_name"),rs.getString("text"));
            views.add(view);
        }
        return views;
    }

    public List<Column> getColumnsFor(String tableName) {
        return null;

    }


}
